﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpGen.Compiler
{
    /// <summary>
    /// Stellt ein Feld-Element dar
    /// </summary>
    public class FieldElement : Element
    {
        /// <summary>
        /// Erzeigt eine neue Instanz der FieldElement-Klasse
        /// </summary>
        /// <param name="element"></param>
        public FieldElement(ClassElement element) : base(element, ElementTypes.Field)
        {

        }

        /// <summary>
        /// Erzeigt eine neue Instanz der FieldElement-Klasse
        /// </summary>
        /// <param name="element"></param>
        public FieldElement(MessageElement element) : base(element, ElementTypes.Field)
        {

        }

        /// <summary>
        /// Liefert den Standartwert
        /// </summary>
        public string DefaultValue { get; set; }

        /// <summary>
        /// Liefert eine Zeichenfolge die das Element darstellt
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(Modifier.ToString());
            stringBuilder.Append(" ");

            if (Type.Type == Types.REFERENCE)
                stringBuilder.Append(Type.ReferenceElement.Elementname);
            else
                stringBuilder.Append(Type.Type.ToString());
            
            stringBuilder.Append(" ");

            stringBuilder.Append(Elementname);
            stringBuilder.Append(" ");

            if (Type.IsList)
                stringBuilder.Append("\n LIST");

            if (DefaultValue != null)
                stringBuilder.Append("\n DEFAULT : " + DefaultValue);

            return stringBuilder.ToString();
        }
    }
}
